package com.zyt.service.impl;

import com.zyt.dao.CategoryMapper;
import com.zyt.dao.TeaMapper;
import com.zyt.pojo.Category;
import com.zyt.pojo.Tea;
import com.zyt.service.CategoryService;
import com.zyt.util.MyBitisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CategoryServiceImpl implements CategoryService {
    @Override
    public List<Category> selectAllCategory() {
        SqlSession sqlSession= null;
        List<Category> categoryList=null;
        try {
            sqlSession= MyBitisUtil.getSession();
            CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
            categoryList= mapper.selectAllCategory();
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            MyBitisUtil.closeSession(sqlSession);
        }
        return categoryList;

    }

    @Override
    public List<Category> selectAllCategoryAndTea() {
        SqlSession sqlSession= null;
        List<Category> categoryList=null;
        try {
            sqlSession= MyBitisUtil.getSession();
            CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
            categoryList= mapper.selectAllCategoryAndTea();
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            MyBitisUtil.closeSession(sqlSession);
        }
        return categoryList;
    }

    @Override
    public void deleteByIdAndC(Integer id) {
        SqlSession sqlSession= null;
        try {
            sqlSession= MyBitisUtil.getSession();
            CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
            mapper.deleteByIdAndC(id);
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            MyBitisUtil.closeSession(sqlSession);
        }
    }
}
